package com.blockchain.front.service.financial.achieve;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.blockchain.common.enums.GdState;
import com.blockchain.common.enums.ZfType;
import com.blockchain.framework.service.ServiceFactory;
import com.blockchain.framework.service.ServiceResource;
import com.blockchain.framework.service.exception.ParameterException;
import com.blockchain.framework.service.query.ArrayParser;
import com.blockchain.framework.service.query.ItemParser;
import com.blockchain.framework.service.query.Paging;
import com.blockchain.framework.service.query.PagingResult;
import com.blockchain.front.config.FrontConst;
import com.blockchain.front.service.common.entity.GdEntity;
import com.blockchain.front.service.financial.GdManage;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.variables.P2PConst;

public class GdManageImpl extends AbstractFinanciaService implements GdManage {

	public static class GdManageFactory implements ServiceFactory<GdManage> {

		@Override
		public GdManage newInstance(ServiceResource serviceResource) {
			return new GdManageImpl(serviceResource);
		}
	}

	public GdManageImpl(ServiceResource serviceResource) {
		super(serviceResource);
	}


	@Override
	public void addGdOrder(GdEntity gdEntity) throws Throwable {
		serviceResource.openTransactions();
		try {
			execute(getConnection(P2PConst.DB_USER),
					"INSERT INTO T6040 SET F02=?,F03=?,F04=?,F05=?,F06=?,F07=?,F08=CURRENT_TIMESTAMP(),F09=?,F10=?,F11=?,F14=?,F15=?,F16=?,F17=?,F18=?,F19=?,F20=?",
					serviceResource.getSession().getAccountId(), gdEntity.gdsl, gdEntity.zfType, gdEntity.skzh,
					gdEntity.gddj,gdEntity.lxdh,gdEntity.gdState,gdEntity.gdsl,gdEntity.zxcjsl,gdEntity.gdsxf,gdEntity.yhmc,gdEntity.sheng,gdEntity.shi,gdEntity.zhmc,gdEntity.khxm,BigDecimal.ZERO);
			BigDecimal sjsl =  gdEntity.gdsl.add(gdEntity.gdsxf);
			selectInt(P2PConst.DB_USER, "SELECT F01 FROM T6023 WHERE F01=? FOR UPDATE", serviceResource.getSession().getAccountId());
			execute(getConnection(P2PConst.DB_USER), "UPDATE T6023 SET F03=F03+?,F04=F04-? WHERE F01=?", sjsl,sjsl, serviceResource.getSession().getAccountId());
		} catch (Exception e) {
			serviceResource.rollback();
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
		
	}


	@Override
	public PagingResult<GdEntity> searchJl(GdState status,Paging paging) throws Throwable {
		StringBuilder sql = new StringBuilder(
				"SELECT T1.F01 AS F01, T2.F02 AS F02, T3.F02 name,")
				.append("T1.F02 AS F04, T1.F03 AS F05,")
				.append("T1.F04 AS F06, T1.F05 AS F07, T1.F06 AS F08, T1.F07 AS F09,")
				.append("T1.F08 AS F10,T1.F09 AS F11,T1.F10 AS F12,T1.F11 AS F13,T1.F12 as F14,T1.F13 as F15,T1.F14 as F16")
				.append(" FROM T6040 T1");
				sql.append(" LEFT JOIN T6010 T2 ON T1.F02 = T2.F01");
				sql.append(" LEFT JOIN T6011 T3 ON T1.F02 = T3.F01  WHERE T1.F02=?");
				ArrayList<Object> parameters = new ArrayList<>();
				parameters.add(serviceResource.getSession().getAccountId());
					if (status != null) {
						sql.append(" AND T1.F09=?");
						parameters.add(status);
					}else {
						sql.append(" AND T1.F09=?");
						parameters.add(GdState.GDZ);
					}
				return selectPaging(getConnection(FrontConst.DB_USER),
						new ArrayParser<GdEntity>() {
							ArrayList<GdEntity> list = new ArrayList<GdEntity>();

							public GdEntity[] parse(ResultSet rst)
									throws SQLException {
								while (rst.next()) {
									GdEntity user = new GdEntity();
									user.id = rst.getInt(1);
									user.loginName = rst.getString(2);
									user.userName = rst.getString(3);
									user.sellId = rst.getInt(4);
									user.gdsl = rst.getBigDecimal(5);
									user.zfType = EnumParser.parse(ZfType.class, rst.getString(6));
									user.skzh = rst.getString(7);
									user.gddj = rst.getBigDecimal(8);
									user.lxdh = rst.getString(9);
									user.gdsj = rst.getTimestamp(10);
									user.gdState = EnumParser.parse(GdState.class, rst.getString(11));
									user.sysl = rst.getBigDecimal(12);
									user.zxcjsl = rst.getBigDecimal(13);
									user.cjsj = rst.getTimestamp(14);
									user.bz = rst.getString(15);
									user.gdsxf = rst.getBigDecimal(16);
									list.add(user);
								}
								return list.toArray(new GdEntity[list.size()]);
							}
						}, paging, sql.toString(), parameters);
	}


	@Override
	public GdEntity get(int id) throws Throwable {
		if (id <= 0) {
			throw new ParameterException("指定的记录不存在.");
		}
		StringBuilder sql = new StringBuilder(
				"SELECT T1.F01 AS F01, T2.F02 AS F02, T3.F02 name,")
		.append("T1.F02 AS F04, T1.F03 AS F05,")
		.append("T1.F04 AS F06, T1.F05 AS F07, T1.F06 AS F08, T1.F07 AS F09,")
		.append("T1.F08 AS F10,T1.F09 AS F11,T1.F10 AS F12,T1.F11 AS F13,T1.F12 as F14,T1.F14 as f15,T1.F15 as f16,T1.F16 as f17,T1.F17 as f18,T1.F18 as f19,T1.F19 as f20")
		.append(" FROM T6040 T1");
		sql.append(" LEFT JOIN T6010 T2 ON T1.F02 = T2.F01");
		sql.append(" LEFT JOIN T6011 T3 ON T1.F02 = T3.F01");
		sql.append(" WHERE T1.F01=?");
		return select(getConnection(FrontConst.DB_USER),
				new ItemParser<GdEntity>() {
					public GdEntity parse(ResultSet rst) throws SQLException {
						GdEntity user = new GdEntity();
						if (rst.next()) {
							user.id = rst.getInt(1);
							user.loginName = rst.getString(2);
							user.userName = rst.getString(3);
							user.sellId = rst.getInt(4);
							user.gdsl = rst.getBigDecimal(5);
							user.zfType = EnumParser.parse(ZfType.class, rst.getString(6));
							user.skzh = rst.getString(7);
							user.gddj = rst.getBigDecimal(8);
							user.lxdh = rst.getString(9);
							user.gdsj = rst.getTimestamp(10);
							user.gdState = EnumParser.parse(GdState.class, rst.getString(11));
							user.sysl = rst.getBigDecimal(12);
							user.zxcjsl = rst.getBigDecimal(13);
							user.cjsj = rst.getTimestamp(14);
							user.gdsxf = rst.getBigDecimal(15);
							user.khxm = rst.getString(20);
							if (user.zfType == ZfType.YHK) {
								user.yhmc = rst.getString(16);
								user.sheng = rst.getString(17);
								user.shi = rst.getString(18);
								user.zhmc = rst.getString(19);
							}
						}
						return user;
					}
				}, sql.toString(), id);
	}


	@Override
	public void updateGd(int id, GdState status, GdEntity gdEntity) throws Throwable {
		serviceResource.openTransactions();
		try {
			if (id <= 0) {
				throw new ParameterException("指定的记录不存在.");
			}
			if (status == GdState.YQX) {
				BigDecimal ycjsl = selectBigDecimal(P2PConst.DB_USER,"SELECT SUM(F03) FROM T6041 WHERE F02=? AND F06=?", gdEntity.id,GdState.JYCG);
				String update = "";
				if (gdEntity.gdsl.compareTo(gdEntity.sysl)==0) {
					update = "UPDATE T6040 SET F09=?,F10=F10-?,F20=F20+? WHERE F01=?";
					execute(getConnection(FrontConst.DB_USER),update,GdState.YQX,gdEntity.sysl,gdEntity.sysl,id);
				}else if(ycjsl!=null && ycjsl.add(gdEntity.sysl).compareTo(gdEntity.gdsl)==0){
					update = "UPDATE T6040 SET F09=?,F10=F10-?,F20=F20+? WHERE F01=?";
					execute(getConnection(FrontConst.DB_USER),update,GdState.YQX,gdEntity.sysl,gdEntity.sysl,id);
				}else {
					update = "UPDATE T6040 SET F10=F10-?,F20=F20+? WHERE F01=?";
					execute(getConnection(FrontConst.DB_USER),update, gdEntity.sysl,gdEntity.sysl,id);
				}
				BigDecimal sjje = gdEntity.sysl.multiply(gdEntity.gdsxf.divide(gdEntity.gdsl,5,BigDecimal.ROUND_HALF_UP)).add(gdEntity.sysl);
				selectInt(P2PConst.DB_USER, "SELECT F01 FROM T6023 WHERE F01=? FOR UPDATE", gdEntity.sellId);
				execute(getConnection(P2PConst.DB_USER), "UPDATE T6023 SET F03=F03-?,F04=F04+? WHERE F01=?", sjje,sjje, gdEntity.sellId);
			}
		} catch (Exception e) {
			serviceResource.rollback();
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
	}


	@Override
	public void gdBuy(int id) throws Throwable {
		if (id <= 0) {
			throw new ParameterException("指定的记录不存在.");
		}
		GdEntity gdEntity = get(id);
		if (gdEntity.gdState != GdState.GDZ) {
			throw new ParameterException("订单不存在或已被拍下.");
		}
		String update = "UPDATE T6040 SET F09=?,F10=?,F11=CURRENT_TIMESTAMP() WHERE F01=?";
		execute(getConnection(FrontConst.DB_USER), update ,GdState.YPX,serviceResource.getSession().getAccountId(),id);
	}


	@Override
	public void qxBuy(int id) throws Throwable {
		if (id <= 0) {
			throw new ParameterException("指定的记录不存在.");
		}
		GdEntity gdEntity = get(id);
		if (gdEntity.buyId != serviceResource.getSession().getAccountId()) {
			throw new ParameterException("你的拍单记录里无此条记录.");
		}
		String update = "UPDATE T6040 SET F09=?,F10=?,F11=? WHERE F01=?";
		execute(getConnection(FrontConst.DB_USER), update ,GdState.GDZ,null,null,id);
	}

	@Override
	public PagingResult<GdEntity> getGdList(Paging paging) throws Throwable {
		StringBuilder sql = new StringBuilder(
				"SELECT T1.F01 AS F01, T2.F02 AS F02, T3.F02 name,")
		.append("T1.F02 AS F04, T1.F03 AS F05,")
		.append("T1.F04 AS F06, T1.F05 AS F07, T1.F06 AS F08, T1.F07 AS F09,")
		.append("T1.F08 AS F10,T1.F09 AS F11,T1.F10 AS F12,T1.F11 AS F13,T1.F12 as F14")
		.append(" FROM T6040 T1");
		sql.append(" LEFT JOIN T6010 T2 ON T1.F02 = T2.F01");
		sql.append(" LEFT JOIN T6011 T3 ON T1.F02 = T3.F01");
		sql.append(" WHERE T1.F09=? AND T1.F10>0");
		//sql.append(" ORDER BY T6040.F08 DESC");
		return selectPaging(getConnection(FrontConst.DB_USER), new ArrayParser<GdEntity>() {
			ArrayList<GdEntity> list = new ArrayList<GdEntity>();
			public GdEntity[] parse(ResultSet re) throws SQLException {
				while (re.next()) {
					GdEntity user = new GdEntity();
					user.id = re.getInt(1);
					user.loginName = re.getString(2);
					user.userName = re.getString(3);
					user.sellId = re.getInt(4);
					user.gdsl = re.getBigDecimal(5);
					user.zfType = EnumParser.parse(ZfType.class, re.getString(6));
					user.skzh = re.getString(7);
					user.gddj = re.getBigDecimal(8);
					user.lxdh = re.getString(9);
					user.gdsj = re.getTimestamp(10);
					user.gdState = EnumParser.parse(GdState.class, re.getString(11));
					user.sysl = re.getBigDecimal(12);
					user.zxcjsl = re.getBigDecimal(13);
					user.cjsj = re.getTimestamp(14);
					list.add(user);
				}
				return list == null ? null : list.toArray(new GdEntity[list.size()]);
			}
		},paging, sql.toString(), GdState.GDZ);
	}


	@Override
	public PagingResult<GdEntity> searchPd(Paging paging) throws Throwable {
		StringBuilder sql = new StringBuilder(
				"SELECT T1.F01 AS F01, T1.F02 AS F02, T1.F03 AS F03,")
		.append("T1.F04 AS F04, T1.F05 AS F05,T1.F06 AS F06,")
		.append("T2.F02 AS F07, T2.F03 AS F08,T2.F04 AS F09,T2.F05 AS F10,T2.F06 AS F11,T2.F07 AS F12,T2.F08 AS F13,")
		.append("T2.F10 AS F14,T2.F11 AS F15,T2.F14 AS F16,T2.F15 AS F17,T2.F16 AS F18,T2.F17 AS F19,T2.F18 AS F20,T2.F19 AS F21,T1.F07 AS F22,T1.F08 AS F23")
		.append(" FROM T6041 T1");
		sql.append(" LEFT JOIN T6040 T2 ON T1.F02 = T2.F01 WHERE T1.F04=? AND T1.F06!=?");
				ArrayList<Object> parameters = new ArrayList<>();
				parameters.add(serviceResource.getSession().getAccountId());
				parameters.add(GdState.YQX);
				return selectPaging(getConnection(FrontConst.DB_USER),
						new ArrayParser<GdEntity>() {
							ArrayList<GdEntity> list = new ArrayList<GdEntity>();

							public GdEntity[] parse(ResultSet rst)
									throws SQLException {
								while (rst.next()) {
									GdEntity user = new GdEntity();
									user.pdid = rst.getInt(1);
									user.id = rst.getInt(2);
									user.pdsl = rst.getBigDecimal(3);
									user.buyId = rst.getInt(4);
									user.pdsj = rst.getTimestamp(5);
									user.pdState = EnumParser.parse(GdState.class, rst.getString(6));
									user.sellId = rst.getInt(7);
									user.gdsl = rst.getBigDecimal(8);
									user.zfType = EnumParser.parse(ZfType.class, rst.getString(9));
									user.skzh = rst.getString(10);
									user.gddj = rst.getBigDecimal(11);
									user.lxdh = rst.getString(12);
									user.gdsj = rst.getTimestamp(13);
									user.sysl = rst.getBigDecimal(14);
									user.zxcjsl = rst.getBigDecimal(15);
									user.gdsxf = rst.getBigDecimal(16);
									if (user.zfType == ZfType.YHK) {
										user.yhmc = rst.getString(17);
										user.sheng = rst.getString(18);
										user.shi = rst.getString(19);
										user.zhmc = rst.getString(20);
									}
									user.khxm = rst.getString(21);
									user.pdrxm = rst.getString(22);
									user.pdrdh = rst.getString(23);
									list.add(user);
								}
								return list.toArray(new GdEntity[list.size()]);
							}
						}, paging, sql.toString(), parameters);
	}


	@Override
	public void pxGd(int id, GdState status, BigDecimal pdsl, String pdrxm, String pdrdh) throws Throwable {
		serviceResource.openTransactions();
		try {
			if (id <= 0) {
				throw new ParameterException("指定的记录不存在.");
			}
			GdEntity gdEntity = get(id);
			if (null == gdEntity || gdEntity.gdState != GdState.GDZ) {
				throw new ParameterException("指定的记录不存在.");
			}
			if (gdEntity.sysl.compareTo(pdsl)<0) {
				throw new ParameterException("拍单数量大于剩余数量.");
			}
			if (gdEntity.zxcjsl.compareTo(pdsl)>0) {
				throw new ParameterException("拍单数量不足.");
			}
			String insert = "INSERT INTO T6041 SET F02=?,F03=?,F04=?,F05=CURRENT_TIMESTAMP(),F06=?,F07=?,F08=?";
			execute(getConnection(FrontConst.DB_USER), insert, id,pdsl,serviceResource.getSession().getAccountId(),GdState.YPX,pdrxm,pdrdh);
			selectInt(P2PConst.DB_USER, "SELECT F01 FROM T6040 WHERE F01=? FOR UPDATE", gdEntity.sellId);
			execute(getConnection(P2PConst.DB_USER), "UPDATE T6040 SET F10=F10-? WHERE F01=?",pdsl, id);
		} catch (Exception e) {
			serviceResource.rollback();
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
	}


	@Override
	public void updatePd(int id, GdState pdState) throws Throwable {
		GdEntity pd = getPd(id);
		serviceResource.openTransactions();
		try {
			if (pdState == GdState.YQX) {
				//取消拍单
				execute(getConnection(P2PConst.DB_USER), "UPDATE T6041 SET F06=? WHERE F01=?",GdState.YQX, id);
				execute(getConnection(P2PConst.DB_USER), "UPDATE T6040 SET F10=F10+? WHERE F01=?",pd.pdsl, pd.id);
			}else if (pdState == GdState.YFK) {
				//已付款
				execute(getConnection(P2PConst.DB_USER), "UPDATE T6041 SET F06=? WHERE F01=?",GdState.YFK, id);
			}else if (pdState == GdState.SSZ) {
				//申诉中
				execute(getConnection(P2PConst.DB_USER), "UPDATE T6041 SET F06=? WHERE F01=?",GdState.SSZ, id);
			}
		} catch (Exception e) {
			serviceResource.rollback();
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
		
	}
	
	/**
	 * 获取拍单信息关联挂单表
	 */
	@Override
	public GdEntity getPd(int id) throws Throwable  {
		if (id <= 0) {
			throw new ParameterException("指定的记录不存在.");
		}
		StringBuilder sql = new StringBuilder(
				"SELECT T1.F01 AS F01, T1.F02 AS F02, T1.F03 AS F03,")
		.append("T1.F04 AS F04, T1.F05 AS F05,T1.F06 AS F06,")
		.append("T2.F02 AS F07, T2.F03 AS F08,T2.F04 AS F09,T2.F05 AS F10,T2.F06 AS F11,T2.F07 AS F12,T2.F08 AS F13,")
		.append("T2.F10 AS F14,T2.F11 AS F15,T2.F14 AS F16,T2.F15 AS F17,T2.F16 AS F18,T2.F17 AS F19,T2.F18 AS F20,T2.F19 AS F21,T1.F07 AS F22,T1.F08 AS F23")
		.append(" FROM T6041 T1");
		sql.append(" LEFT JOIN T6040 T2 ON T1.F02 = T2.F01 WHERE T1.F01=?");
		return select(getConnection(FrontConst.DB_USER),
				new ItemParser<GdEntity>() {
					public GdEntity parse(ResultSet rst) throws SQLException {
						GdEntity user = new GdEntity();
						if (rst.next()) {
							user.pdid = rst.getInt(1);
							user.id = rst.getInt(2);
							user.pdsl = rst.getBigDecimal(3);
							user.buyId = rst.getInt(4);
							user.pdsj = rst.getTimestamp(5);
							user.pdState = EnumParser.parse(GdState.class, rst.getString(6));
							user.sellId = rst.getInt(7);
							user.gdsl = rst.getBigDecimal(8);
							user.zfType = EnumParser.parse(ZfType.class, rst.getString(9));
							user.skzh = rst.getString(10);
							user.gddj = rst.getBigDecimal(11);
							user.lxdh = rst.getString(12);
							user.gdsj = rst.getTimestamp(13);
							user.sysl = rst.getBigDecimal(14);
							user.zxcjsl = rst.getBigDecimal(15);
							user.gdsxf = rst.getBigDecimal(16);
							if (user.zfType == ZfType.YHK) {
								user.yhmc = rst.getString(17);
								user.sheng = rst.getString(18);
								user.shi = rst.getString(19);
								user.zhmc = rst.getString(20);
							}
							user.khxm = rst.getString(21);
							user.pdrxm = rst.getString(22);
							user.pdrdh = rst.getString(23);
						}
						return user;
					}
				}, sql.toString(), id);
	}


	@Override
	public GdEntity[] getPdson(int id) throws Throwable {
		StringBuilder sql = new StringBuilder(
				"SELECT T1.F01 AS F01, T1.F02 AS F02, T1.F03 AS F03,")
		.append("T1.F04 AS F04, T1.F05 AS F05,T1.F06 AS F06,")
		.append("T2.F02 AS F07, T2.F03 AS F08,T2.F04 AS F09,T2.F05 AS F10,T2.F06 AS F11,T2.F07 AS F12,T2.F08 AS F13,")
		.append("T2.F10 AS F14,T2.F11 AS F15,T2.F14 AS F16,T2.F15 AS F17,T2.F16 AS F18,T2.F17 AS F19,T2.F18 AS F20,T2.F19 AS F21,T1.F07 AS F22,T1.F08 AS F23")
		.append(" FROM T6041 T1");
		sql.append(" LEFT JOIN T6040 T2 ON T1.F02 = T2.F01 WHERE T1.F02=? AND T1.F06!=?");
				ArrayList<Object> parameters = new ArrayList<>();
				parameters.add(id);
				parameters.add(GdState.YQX);
				return selectAll(getConnection(FrontConst.DB_USER),
						new ArrayParser<GdEntity>() {
							ArrayList<GdEntity> list = new ArrayList<GdEntity>();

							public GdEntity[] parse(ResultSet rst)
									throws SQLException {
								while (rst.next()) {
									GdEntity user = new GdEntity();
									user.pdid = rst.getInt(1);
									user.id = rst.getInt(2);
									user.pdsl = rst.getBigDecimal(3);
									user.buyId = rst.getInt(4);
									user.pdsj = rst.getTimestamp(5);
									user.pdState = EnumParser.parse(GdState.class, rst.getString(6));
									user.sellId = rst.getInt(7);
									user.gdsl = rst.getBigDecimal(8);
									user.zfType = EnumParser.parse(ZfType.class, rst.getString(9));
									user.skzh = rst.getString(10);
									user.gddj = rst.getBigDecimal(11);
									user.lxdh = rst.getString(12);
									user.gdsj = rst.getTimestamp(13);
									user.sysl = rst.getBigDecimal(14);
									user.zxcjsl = rst.getBigDecimal(15);
									user.gdsxf = rst.getBigDecimal(16);
									if (user.zfType == ZfType.YHK) {
										user.yhmc = rst.getString(17);
										user.sheng = rst.getString(18);
										user.shi = rst.getString(19);
										user.zhmc = rst.getString(20);
									}
									user.khxm = rst.getString(21);
									user.pdrxm = rst.getString(22);
									user.pdrdh = rst.getString(23);
									list.add(user);
								}
								return list.toArray(new GdEntity[list.size()]);
							}
			}, sql.toString(), parameters);
	}


	@Override
	public void updateGdSon(int id, GdState status) throws Throwable {
		serviceResource.openTransactions();
		try {
			if (id <= 0) {
				throw new ParameterException("指定的记录不存在.");
			}
			if(status == GdState.JYCG){
				GdEntity gdEntity = getPd(id);
				if (gdEntity.sysl.compareTo(BigDecimal.ONE)<0) {
					execute(getConnection(FrontConst.DB_USER), "UPDATE T6040 SET F09=? WHERE F01=?", GdState.JYCG,gdEntity.id);
				}
				BigDecimal sxfl = gdEntity.gdsxf.divide(gdEntity.gdsl,5,BigDecimal.ROUND_HALF_UP);
				String update = "UPDATE T6041 SET F06=? WHERE F01=?";
				execute(getConnection(FrontConst.DB_USER), update, status,id);
				selectInt(P2PConst.DB_USER, "SELECT F01 FROM T6023 WHERE F01=? FOR UPDATE", gdEntity.sellId);
				execute(getConnection(P2PConst.DB_USER), "UPDATE T6023 SET F02=F02-?,F03=F03-? WHERE F01=?", gdEntity.pdsl, gdEntity.pdsl.add(gdEntity.pdsl.multiply(sxfl)), gdEntity.sellId);
				selectInt(P2PConst.DB_USER, "SELECT F01 FROM T6023 WHERE F01=? FOR UPDATE", gdEntity.buyId);
				execute(getConnection(P2PConst.DB_USER), "UPDATE T6023 SET F02=F02+?,F04=F04+? WHERE F01=?", gdEntity.pdsl, gdEntity.pdsl, gdEntity.buyId);
			}
		} catch (Exception e) {
			serviceResource.rollback();
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
	}
	
}